]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
runDialog: catch exceptions from Gio.app_info_launch_default_for_uri()
authorRui Matos <tiagomatos@gmail.com>
Wed, 6 Jul 2011 19:43:49 +0000 (20:43 +0100)
committerRui Matos <tiagomatos@gmail.com>
Tue, 19 Jul 2011 23:25:11 +0000 (00:25 +0100)
An uncaught exception here would mean that the dialog wouldn't close.

https://bugzilla.gnome.org/show_bug.cgi?id=653700

js/ui/runDialog.js

index 5152ecb7b39e267dcf41d21974c4e16b1e0f2695..bd6fc25ae5d5b0d581e31c2d848c7eb255ab02e5 100644 (file)
@@ -333,33 +333,46 @@ __proto__: ModalDialog.ModalDialog.prototype,
 
                 if (GLib.file_test(path, GLib.FileTest.EXISTS)) {
                     let file = Gio.file_new_for_path(path);
-                    Gio.app_info_launch_default_for_uri(file.get_uri(),
-                                                        global.create_app_launch_context());
-                } else {
-                    this._commandError = true;
-
-                    this._errorMessage.set_text(e.message);
-
-                    if (!this._errorBox.visible) {
-                        let [errorBoxMinHeight, errorBoxNaturalHeight] = this._errorBox.get_preferred_height(-1);
-
-                        let parentActor = this._errorBox.get_parent();
-                        Tweener.addTween(parentActor,
-                                         { height: parentActor.height + errorBoxNaturalHeight,
-                                           time: DIALOG_GROW_TIME,
-                                           transition: 'easeOutQuad',
-                                           onComplete: Lang.bind(this,
-                                               function() {
-                                                    parentActor.set_height(-1);
-                                                    this._errorBox.show();
-                                               })
-                                         });
+                    try {
+                        Gio.app_info_launch_default_for_uri(file.get_uri(),
+                                                            global.create_app_launch_context());
+                    } catch (e) {
+                        // The exception from gjs contains an error string like:
+                        //     Error invoking Gio.app_info_launch_default_for_uri: No application
+                        //     is registered as handling this file
+                        // We are only interested in the part after the first colon.
+                        let message = e.message.replace(/[^:]*: *(.+)/, '$1');
+                        this._showError(message);
                     }
+                } else {
+                    this._showError(e.message);
                 }
             }
         }
     },
 
+    _showError : function(message) {
+        this._commandError = true;
+
+        this._errorMessage.set_text(message);
+
+        if (!this._errorBox.visible) {
+            let [errorBoxMinHeight, errorBoxNaturalHeight] = this._errorBox.get_preferred_height(-1);
+
+            let parentActor = this._errorBox.get_parent();
+            Tweener.addTween(parentActor,
+                             { height: parentActor.height + errorBoxNaturalHeight,
+                               time: DIALOG_GROW_TIME,
+                               transition: 'easeOutQuad',
+                               onComplete: Lang.bind(this,
+                                                     function() {
+                                                         parentActor.set_height(-1);
+                                                         this._errorBox.show();
+                                                     })
+                             });
+        }
+    },
+
     open: function() {
         this._history.lastItem();
         this._errorBox.hide();